const { defineConfig } = require("@vue/cli-service");
const TerserPlugin = require("terser-webpack-plugin");
const path = require("path");
function resolve(dir) {
  return path.join(__dirname, dir);
}
const name = process.env.VUE_APP_TITLE || "水声数据分析系统"; // 网页标题
module.exports = defineConfig({
  transpileDependencies: true,
  chainWebpack: (config) => {
    // 移除 prefetch 插件
    config.plugins.delete("preload");
    config.plugins.delete("prefetch");
  },
  productionSourceMap: false,
  devServer: {
    open: true,
    // port: 8801, // 自定义修改8080端口
    proxy: {
      [process.env.VUE_APP_BASE_API]: {
        // target: "http://4v60394w24.qicp.vip",//用jar包时访问
        // target: "http://192.168.3.136:8080",
        // target: "http://4v60394w24.qicp.vip",
        target: "http://172.16.20.222:8080",
        // target: "http://59.110.55.56:8080",
        // target: "http://192.168.43.191:8080",
        changeOrigin: true,
        pathRewrite: {
          ["^" + process.env.VUE_APP_BASE_API]: "",
        },
      },
      "/ws-api": {
        target: "ws://4v60394w24.qicp.vip",
        changeOrigin: true, // 是否允许跨域
        ws: true,
      },
    },
    client: {
      overlay: false, // 编译错误时，取消全屏覆盖（建议关掉）
    },
  },
  publicPath: "/",
  outputDir: "dist", //build输出目录
  assetsDir: "assets", //静态资源目录（js, css, img）
  lintOnSave: false, //是否开启eslintwebsocket
  configureWebpack: {
    name: name,
    resolve: {
      alias: {
        "@": resolve("src"),
      },
    },
    plugins: [
      new TerserPlugin({
        terserOptions: {
          ecma: undefined,
          warnings: false,
          parse: {},
          compress: {
            drop_console: true,
            drop_debugger: false,
            pure_funcs: ["console.log"], // 移除console
          },
        },
      }),
    ],
  },
});
